home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-04-08 | 7.7 KB | 243 lines | [TEXT/MPS ] |
- ;====================================================================================
- ;
- ; HackRecorderInit.a
- ;
- ; Copyright © 1990 Apple Computer, Inc.
- ;
- ; Sound Input Driver Example
- ;
- ; Revision History
- ;
- ; 04/01/91 No changes except added this comment line: Submitted as item for developer CD.
- ; 11/19/90 First created.
- ;
- ;====================================================================================
-
- INCLUDE 'Traps.a'
- INCLUDE 'SysErr.a'
- INCLUDE 'SysEqu.a'
- INCLUDE 'Sound.a'
-
- CASE OBJ
- STRING PASCAL
- MACHINE MC68000
-
- Lvl7Mask EQU $0700 ; used to keep out all non-maskable interrupts.
-
- ;_______________________________________________________________________
- ;
- ; Routine: Start
- ; Start is the entry point of this INIT.
- ; It loads the 'DRVR' resource into memory, finds an available "slot" in
- ; the Unit Table (properly expanding it if necessary), and installs the driver.
- ;
- ; Registers Used:
- ; A0 -- Temp, Ptr to DCE
- ; A1 -- Ptr to Unit Table
- ; A2 -- Used to JSR to driver's Open routine
- ; A3 -- Handle to DRVR
- ;
- ; D0 -- Temp, Driver RefNum
- ; D1 -- Offset into Unit Entry Table where we install the driver
- ; D2 -- Temp
- ; D3 -- Used to save Driver RefNum for SPBSignIn
- ;_______________________________________________________________________
-
- Start Main Export
-
- ; Get the DRVR resource and keep it in memory
-
- CLR.L -(SP) ; push space for handle result on stack
- MOVE.L #'DRVR', -(SP) ; push ResType param on stack
- LEA @drvrName, A0
- MOVE.L A0, -(SP) ; push ptr to name string on stack
- _GetNamedResource ; get handle to our DRVR in memory
- MOVE.L (SP)+, A3 ; get handle off stack
- MOVE.L A3, D0 ; AND test it
- BEQ @outOfHere
- MOVE.L A3, -(SP) ; handle is good so push it back on stack
- _DetachResource
- MOVE.L A3, A0
- _MoveHHi ; get it up out of the way before locking it
- MOVE.L A3, A0 ; get handle to our DRVR
- _HLock ; lock down the driver
-
- ; Find a slot for the driver & expand the unit table if necessary
-
- MOVE.W #(48*4),D1 ; offset into unit table for unit 48
- MOVE.W #-49,D0 ; refnum matching unit -49
-
- MOVEM.L A0/D0, -(SP) ; save regs that GetPtrSize uses
- MOVEA.L UTableBase, A0 ; GetPtrSize wants Ptr in A0
- _GetPtrSize
- MOVE.L D0, D2 ; Save Result
- MOVEM.L (SP)+, A0/D0 ; Restore regs
- BMI @outOfHere ; error
- LSR.W #1, D2
- LSR.W #1, D2 ; Div by 4 to compare with Unit Table Size
- MOVE.W UnitNtryCnt, D3
- CMP.W D2, D3
- BEQ.S @UnitNtryCntIsCorrect
- MOVE.W D2, UnitNtryCnt ; Fix it
-
- @UnitNtryCntIsCorrect
- CMP.W #48, UnitNtryCnt
- BGT.S @LookForSlot
-
- ; Resize unit table
-
- MOVEM.L D0, -(SP) ; save D0, ResizeUnitTable uses D0, but we're using it
- MOVE.W UnitNtryCnt, D2
- ADD.W #16, D2 ; Now add 16 more slots to Unit Table
- MOVE.W D2, -(SP) ; push requested # of SLOTS for new Unit Table
- JSR ResizeUnitTable ; Resize Unit table & update UnitNtryCnt
- ADDQ #2, SP ; balance stack
- MOVE.W D0, D0
- MOVEM.L (SP)+, D0
- BMI @outOfHere ; error
- ; NOW:
- ; D1 has offset into unit table for unit #48
- ; D0 has refnum matching unit #-49
- ; AND, we know that this spot is avaiable, because we just created it.
- ; SO...
- BRA.S @emptyEntry
-
-
- @LookForSlot
- MOVE.L UTableBase,A1 ; get ptr to unit table
- @nextEntry TST.L 0(A1,D1) ; check for empty unit table entry[D1/4]
- BEQ.S @emptyEntry
- ADDQ.W #4, D1 ; inc unit table offset to next entry
- SUBQ.W #1, D0 ; dec refNum to match inc'ed unit number
- MOVE.W D1, D2
- LSR.W #1, D2
- LSR.W #1, D2 ; Div by 4 to compare with Unit Table Size
- CMP.W UnitNtryCnt, D2
- BGE.S @SpotNotFound
- BRA.S @nextEntry
-
- @SpotNotFound
- ; Resize unit table
-
- MOVE.W UnitNtryCnt, D2
- ADD.W #16, D2
- MOVE.W D2, -(SP) ; push requested # of SLOTS for new Unit Table
- JSR ResizeUnitTable ; Resize Unit table & update UnitNtryCnt
- ADDQ #2, SP ; balance stack
- TST.W D0
- BMI.S @outOfHere ; error
-
- MOVE.W UnitNtryCnt, D1 ; get max SLOTS
- SUB.W #16, D1 ; we want the first one that we just created
- MOVE.W D1, D0 ; save in D0 for refNum
- LSL.W #1, D1 ; Mul by 4
- LSL.W #1, D1 ; to get offset into UTable
- ADDQ #1, D0 ; Update coresponding refnum
- NEG.W D0
- ; NOW:
- ; D1 has offset into unit table
- ; D0 has refnum matching unit
- ; AND, we know that this spot is avaiable, because we just created it.
- ; SO...
- ; BRA.S @emptyEntry ; let this drop through
-
- @emptyEntry
- MOVE.L D0, D4 ; sock away the refNum so our DRVR can get it later
-
- MOVE.L A3,A0 ; get handle to our DRVR
- MOVE.L (A0),A0 ; get Ptr to our DRVR
- MOVE.L UTableBase,A1 ; get ptr to unit table
- MOVE.L A1,-(SP) ; save unit table ptr
- _DrvrInstall ,sys ; A0=Ptr to our DRVR, D0=DRVR refNum to use
-
- MOVE.L (SP)+,A1 ; restore unit table ptr
- MOVE.L 0(A1,D1),A0 ; get handle to DCEntry from unit table
- MOVE.L A0,-(SP) ; save DCEntry ptr
- _HLock ; lock down the DCE (handle is still on stack)
-
- MOVE.L (SP)+,A0 ; restore DCEntry ptr
- MOVE.L (A0),A0 ; get Ptr to DCE
- MOVE.L A3,A1 ; get handle to DRVR
- MOVE.L (A1),A1 ; get Ptr to DRVR
- MOVE.L A1,dCtlDriver(A0) ; and into DCE
- MOVE.W drvrFlags(A1),dCtlFlags(A0) ; put drvrFlags into DCE
-
- MOVE.W drvrDelay(A1),dCtlDelay(A0) ; put drvrDelay into DCE
- MOVE.W drvrEMask(A1),dCtlEMask(A0) ; put drvrEMask into DCE
- MOVE.W drvrMenu(A1),dCtlMenu(A0) ; put drvrMenu into DCE
-
- MOVEQ.L #0,D0
- MOVE.W drvrOpen(A1),D0 ; get offset to open routine
- ADD.L A1,D0 ; get Ptr to open routine
- MOVE.L D0,A2 ; put it in an A reg so we can JSR to it
-
- MOVE.L A0,A1 ; put DCE into A1 to fake out Open DRVR call
- BSET.B #dOpened,dCtlFlags+1(A1) ; set dCtlFlags to Opened for driver DCE
- JSR (A2) ; JSR to this DRVR's Open Routine
-
- ; Sign-in device with the Sound Input Manager
-
- CLR.W -(SP) ; result int
- MOVE.W D4,-(SP) ; ioRefNum of this DRVR
-
- LEA @deviceName,A0
- MOVE.L A0,-(SP) ; Ptr to device name
- _CallSoundIn SPBSignInDevice ; this macro is found in Traps.a
- MOVE.W (SP)+,D0
-
- @outOfHere
- RTS
-
- STRING PASCAL
- @drvrName DC.B '.HackRecorder' ; driver name
- @deviceName DC.B 'HackRecorder' ; input device name
- ALIGN 2
-
- ;_______________________________________________________________________
- ;
- ; Routine: ResizeUnitTable
- ;
- ; Stack Params:
- ; (Word) -- Requested Size of Unit Table IN SLOTS (not bytes)
- ;
- ; Registers Used:
- ;
- ;
- ;
- ;_______________________________________________________________________
-
- EXPORT ResizeUnitTable
-
- ResizeUnitTable
- LINK A6,#0
- MOVEM.L A0-A1/D1, -(SP) ; Save used registers.
-
- MOVE.W 8(A6), D1 ; Get Size in SLOTS
- MOVE.W D1, D0
- MULU.W #4, D0 ; turn into size in bytes
- _NewPtr ,sys,clear ; crate clear block in sys heap
- BNE.S @MemoryError ; D0 contains error code, A0 contains Ptr
-
- MOVE SR, -(SP) ; Save old SR
- ORI #Lvl7Mask, SR ; disable interrupts
- MOVEA.L A0, A1 ; put ptr to new table into A1
- MOVEA.L UTableBase, A0 ; put ptr to old table into A0
- MOVE.W UnitNtryCnt, D0 ; get number of entries in old table
- MULU.W #4, D0 ; size of old table
- _BlockMove ; copy old table to new table
- _DisposPtr ; get rid of old table
- MOVE.L A1, UTableBase ; update UTableBase
- MOVE.W D1, UnitNtryCnt ; update number of entries
- MOVE (SP)+, SR ; restore old interrupt status
- CLR.L D0 ; return noErr
-
- @MemoryError
-
- MOVEM.L (SP)+, A0-A1/D1 ; Restore used registers.
- UNLK A6
- RTS
-
- EndProc
-
- End
-